package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.ReportService;
import com.itheima.health.vo.GetBusinessReportDataParam;
import com.itheima.health.vo.MemberReportVO;
import com.itheima.health.vo.SetmealReportExcelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据报告控制器
 */
@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "数据报告展示接口")
public class ReportController {

    @Autowired
    private ReportService reportService;
    @GetMapping("/getBusinessReportData")
    @ApiOperation("运营统计")
    public Result statistics(){
        GetBusinessReportDataParam s = reportService.statis();
        return new Result(true,MessageConst.ACTION_SUCCESS,s);
    }

    @GetMapping("/getMemberReport")
    public Result memberReport(){
        log.info("根据时间，进行会员数据统计");
        MemberReportVO reportVO=reportService.getmember();
        Map<String,Object> map=new HashMap<>();
        map.put("months",reportVO.getDateList());
        map.put("memberCount",reportVO.getMemberList());
        return new Result(true,MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
    }

    /**
     * 获取套餐统计数据(饼图)
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport(){
        // 去service层进行查询并返回相关信息VO
        SetmealReportExcelVO setmealReportList = reportService.getSetmealReport();
        return new Result(true, MessageConst.GET_SETMEAL_COUNT_REPORT_SUCCESS, setmealReportList);
    }

    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出数据运营报表")
    public void export(HttpServletResponse response){
        reportService.exportBusiness(response);
    }
}
